<!DOCTYPE html>
<html>
<head>
    <title>Hierarchical data binding</title>
    <meta charset="utf-8">
    <link href="../content/shared/styles/examples-offline.css" rel="stylesheet">
    <link href="../../styles/kendo.common.min.css" rel="stylesheet">
    <link href="../../styles/kendo.rtl.min.css" rel="stylesheet">
    <link href="../../styles/kendo.default.min.css" rel="stylesheet">
    <link href="../../styles/kendo.dataviz.min.css" rel="stylesheet">
    <link href="../../styles/kendo.dataviz.default.min.css" rel="stylesheet">
    <link href="../../styles/kendo.mobile.all.min.css" rel="stylesheet" />
    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/kendo.all.min.js"></script>
    <script src="../content/shared/js/console.js"></script>
    <script>
        
    </script>
    
    
</head>
<body>
    
        <a class="offline-button" href="../index.html">Back</a>
    
    <div data-role="view" data-show="rebindListView" id="hierarchical-view" data-transition="slide">
    <header data-role="header">
        <div data-role="navbar" id="employee-navbar">
            <a data-role="backbutton" id="employee-back" data-align="left">Back</a>
            <span data-role="view-title"></span>
            <a data-align="right" data-role="button" class="nav-button" href="#/">Index</a>
        </div>
    </header>
    <ul id="hierarchical-listview" data-role="listview" data-template="hierarchicalMobileListViewTemplate"></ul>
</div>

<style>
    #hierarchical-listview .employee-image {
        width: 4em;
        height: 4.4em;
        margin: 0;
        border: 1px solid rgba(0,0,0,.2);
        -webkit-border-radius: 4em;
        border-radius: 4em;
        display: inline-block;
        -webkit-background-size: auto 100%;
        background-size: auto 100%;
        background-repeat: no-repeat;
        background-position: center center;
        -webkit-transform: translatez(0);
        vertical-align: middle;
    }

    #hierarchical-listview h2 {
        display: inline-block;
        margin: .5em;
        font-size: 1.1em;
    }

    .km-android #hierarchical-listview .parent:after {
        display: inline-block;
        border-color: #ffffff;
    }
    .km-wp #hierarchical-listview .parent:after {
        display: inline-block;
        border-color: #cccccc;
    }
</style>
<script id="hierarchicalMobileListViewTemplate" type="text/x-kendo-template">
    # if (data.HasEmployees) { #
        <a href="\#hierarchical-view?parent=#: data.id #" class="parent">
            <span class="employee-image" style="background-image: url('../content/web/Employees/#: id #.jpg')"></span>
            <h2> #: FullName # </h2>
        </a>
    # } else { #
        <span class="employee-image" style="background-image: url('../content/web/Employees/#: id #.jpg')"></span>
        <h2> #: FullName # </h2>
    # } #
</script>

<script>


    var serviceRoot = "http://demos.telerik.com/kendo-ui/service";

    var employees = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                url: serviceRoot + "/Employees",
                dataType: "jsonp"
            }
        },

        schema: {
            model: {
                id: "EmployeeId",
                hasChildren: "HasEmployees"
            }
        }
    });

    function rebindListView(e) {
        var parentID = e.view.params.parent,
            element = e.view.element,
            backButton = element.find('#employee-back'),
            listView = element.find("#hierarchical-listview").data('kendoMobileListView'),
            navBar = element.find('#employee-navbar').data('kendoMobileNavBar');

        if (parentID) {
            employees.fetch(function() {
                var item = employees.get(parentID);
                if (item) {
                    backButton.show();
                    navBar.title(item.FullName);
                    listView.setDataSource(item.children);
                } else {
                    // redirect to root
                    setTimeout(function() {
                        kendo.mobile.application.navigate('#hierarchical-view');
                    }, 0);
                }
            });
        } else {
            backButton.hide();
            navBar.title('Employees');
            listView.setDataSource(employees);
        }

        e.view.scroller.scrollTo(0, 0);
    }
</script>


    
    <script>
        window.kendoMobileApplication = new kendo.mobile.Application(document.body);
    </script>
    
    
</body>
</html>
